﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cuckoo.TaskSchedule
{
	/// <summary>
	/// 计时器工厂
	/// </summary>
	public class TimerFactory
	{
		/// <summary>
		/// 获取计时器对象
		/// </summary>
		/// <returns></returns>
		public static ITimer CreateTimer(ITask task)
		{
			ITimer timer = null;
			switch (TaskStrategyHelper.GetType(task))
			{
				case TaskType.INTERNAL_TASK:
					timer = new IntervalTimer(); break;
				case TaskType.SOLID_TASK:
					timer = new FixedTimer(); break;
			}
			GetBaseTimer().SecondTrigger += timer.OnSecondTrigger;
			timer.Work();
			return timer;
		}

		/// <summary>
		/// 获得基础计时器
		/// </summary>
		/// <returns></returns>
		public static ITimer GetBaseTimer()
		{
			return BaseTimer.Instance;
		}
	}
}
